define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'yalimedia/coursequestion/index?ids='+$("#table").attr('data-id'),
                    multi_url: 'yalimedia/coursequestion/multi',
                    del_url: 'yalimedia/coursequestion/del',
                    table: 'yalimedia_course_question',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                sortOrder:'desc',
                columns: [
                    [
                        {checkbox: true},
                        {
                            field: 'question.kind',
                            title: __('试题类型'),
                            searchList: {"JUDGE": __('判断题'), "SINGLE": __('单选题'), "MULTI": __('多选题'), "FILL": __('填空题'), "SHORT": __('问答题'), "MATERIAL": __('材料题'), "WORD": __('词汇题'),"CALL": __('通话题')},
                            formatter: Table.api.formatter.normal,
                        },
                        {field: 'question.title', title: __('题目'), autocomplete: false, operate: 'LIKE', formatter: function (value) {
                            return value.length > 40 ? value.substr(0, 40) + '...' : value;
                        }},
                        {
                            field: 'question.difficulty',
                            title: __('难度'),
                            searchList: {"EASY": __('简单'), "GENERAL": __('普通'), "HARD": __('困难')},
                            formatter: Table.api.formatter.normal
                        },
                        {
                            field: 'question.status',
                            title: __('状态'),
                            searchList: {"NORMAL": __('正常'), "HIDDEN": __('隐藏')},
                            formatter: Table.api.formatter.status,
                            operate: false
                        },
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});